package com.VisualDisp.QuadCalculateProject.Calculations.Equations;

public class Expressions {

	private BaseEquation eq;
	private Result resu;
	private double a,b,c;
	
	public Expressions(double a, double b, double c)
	{
		this.a = a;
		this.b = b;
		this.c = c;
		eq = decideType();
		resu = eq.calculateExp();	
	}
	
	public BaseEquation getEquation()
	{
		return this.eq;
	}
	
	private boolean allZero()
	{
		return (aZero() && bZero() && cZero());
	}	
	private boolean abZero()
	{
		return (aZero()&&bZero()&&!cZero());
	}	
	private boolean acZero()
	{
		return(aZero() && cZero()&&!bZero());
	}	
	private boolean bcZero()
	{
		return(!aZero()&& bZero() && cZero());
	}
	private boolean aZero()
	{
		return a == 0;
	}	
	private boolean bZero()
	{
		return b == 0;
	}
	private boolean cZero()
	{
		return c == 0;
	}
	
	public Result getResult()
	{
		return resu;
	}
	
	public String getSEquation()
	{
		return eq.getEquation();
	}
	
	public String getType()
	{
		return eq.getType();
	}
	private BaseEquation decideType()
	{
		if(allZero())
			return new TrueExp();
		else
		{
			if(abZero())
				return new FalseExp(c);
			else if(acZero())
				return new LinearEquation(b, 0);
			else if(bcZero())
				return new SquareEquation(a,0);
			else
			{
				if(aZero())
					return new LinearEquation(b, c);
				else if(bZero())
					return new SquareEquation(a, c);
				else if(cZero())
				{
					return new TwoXSquare(a,b);
				}
				else
				{
					return new QuadEquation(a, b, c);
				}
				
			}
			
		}
	}
}

